#include <boost/python.hpp>
#include <iostream>
#include <pyxx/python_error.h>

class my_error : public std::runtime_error
{
    public:
        my_error(std::string msg):
            std::runtime_error(msg)
            {}


        static const char * TranslateThis(int code) {return "1";}
        static const char * TranslateThat(int code) {return "2";}
};


void throw_fit()
{
    throw my_error("fit");
}

void callme(boost::python::object obj)
{
    obj();
}

bool catcher(boost::python::object obj)
{
    try
    {
        try
        {
            obj();
            return false;
        }
        catch(boost::python::error_already_set&)
        {
            python_error::raise();
        }
    }
    catch(my_error&)
    {
        return true;
    }
    assert(false);
    return false;
}

void internal(boost::python::object obj)
{
    try
    {
        try
        {
            obj();

        }
        catch( boost::python::error_already_set&)
        {
            python_error::raise();
        }
    }
    catch(IPythonError & err)
    {
        
/*        boost::python::import("sys").attr("stdout").attr("write")("Caught it!");
        err.restore();
        boost::python::throw_error_already_set();*/
    }
}
